<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cn.firstsoft.firstframe.admin.PropertyFile"%>
<%@ page import="cn.firstsoft.firstframe.admin.XmlFile"%>
<%@ page import="cn.firstsoft.firstframe.admin.Field"%>
<%@ page import="org.springside.core.Constants"%>
<%@ page import="cn.firstsoft.modules.portlet.PortletNewConstants"%>
<%@ page import="cn.firstsoft.firstframe.web.FirstFrameBeanFactory"%>
<%@ page import="org.springside.modules.security.service.logic.RoleManager"%>
<%@ page import="org.springside.modules.security.service.logic.DeptManager"%>
<%@ page import="org.springside.modules.security.service.logic.AreaManager"%>
<%@ page import="cn.firstsoft.modules.portlet.service.logic.PortletNewManager"%>
<%@page import="org.apache.tools.ant.util.Base64Converter"%>
<%@page import="com.kingdee.seil.util.Base64"%>
<jsp:directive.page import="cn.firstsoft.firstframe.plugins.compass.service.logic.CompassIndexBuilderManager"/>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="../common.jsp"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>    
    <title></title>
  </head>
  
  <body>
  	
    <%
    	request.setCharacterEncoding("utf-8");
    	String type = request.getParameter("type")==null?"":request.getParameter("type");
    	List list = XmlFile.findFields(type);
    	String flag = "";
    	String errMsg = "";
    	for(int i=0;i<list.size();i++)
    	{
    		Field field = (Field)list.get(i);
    		
    		String name = field.getName();
    		String tmp_value = request.getParameter(name) == null?"":request.getParameter(name);
    		String value = new String(tmp_value.getBytes("iso-8859-1"),"utf-8");
    		
    		//当分权管理被取消时按需求要求给所有单位管理员发送通知消息，只能在此特殊判断
    		if(Constants.SEPARATION_OF_POWERS && field.getPname().equals("constant.separation_of_powers") && !Boolean.valueOf(value)){
   				DeptManager deptManager = (DeptManager)FirstFrameBeanFactory.getBean("deptManager");
   				if(deptManager.getAllUcSize()>1){
   					errMsg = "应先取消其他所有的管理单元才可禁用分权管理!";
   					flag = "false";
   				}else{
   					flag += PropertyFile.writeProperties("firstframe.properties",field.getPname(),value);
   					RoleManager roleManager = (RoleManager)FirstFrameBeanFactory.getBean("roleManager");
       				roleManager.removePermInRole(2," 分权管理被禁用，您的单元管理员权限被取消！","请知悉");
   				}
    		}else if(!Constants.SEPARATION_OF_POWERS && field.getPname().equals("constant.separation_of_powers") && Boolean.valueOf(value)){
    			AreaManager areaManager = (AreaManager)FirstFrameBeanFactory.getBean("areaManager");
    			areaManager.saveAdminByRootArea();
    			flag += PropertyFile.writeProperties("firstframe.properties",field.getPname(),value);
    		}else{
    			flag += PropertyFile.writeProperties("firstframe.properties",field.getPname(),value);
    		}

    	}
    	
    	if(flag.contains("false"))
		{
			response.sendRedirect("setting_edit.jsp?flag=err&type="+type+"&errMsg="+Base64.encode(errMsg.getBytes()));
		}
		else{
			response.sendRedirect("setting_edit.jsp?flag=suc&type="+type);
		}
    %>
   
    
  </body>
</html>
